package com.example.cloudprinter.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

public class EncodeUtils {

    public static String getSin(String client_id, String client_secret) {
        try {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(client_id);
            stringBuilder.append(System.currentTimeMillis() / 1000);
            stringBuilder.append(client_secret);
            return getMd5(stringBuilder.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    /**
     * @param str
     * @return
     * @Description: 32位小写MD5
     */
    public static String getMd5(String str) {
        String reStr = "";
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(str.getBytes());
            StringBuffer stringBuffer = new StringBuffer();
            for (byte b : bytes) {
                int bt = b & 0xff;
                if (bt < 16) {
                    stringBuffer.append(0);
                }
                stringBuffer.append(Integer.toHexString(bt));
            }
            reStr = stringBuffer.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return reStr;
    }

    public static String getuuid() {
        return UUID.randomUUID().toString();
    }
}
